import axios from 'axios';
import { message } from 'antd';
import { Auth_Token, baseURL } from './config';

const request = axios.create({ baseURL });

request.interceptors.request.use((config) => {
    config.headers['Auth-Token'] = Auth_Token;
    return config;
});

request.interceptors.response.use((res) => {
    const { data } = res.data;
    return data;
}, (error) => {
    if (error.response) {
        const { data } = error.response;
        message.error(`异常：${data.message}`);
    } else {
        message.error('异常！');
    }
});

export default request;
